package com.nclg.exam.controller;

import com.github.pagehelper.PageInfo;
import com.nclg.exam.dto.ReviewPaperDto;
import com.nclg.exam.dto.UserPaperDto;
import com.nclg.exam.dto.UserPaperListDto;
import com.nclg.exam.entity.LayResponse;
import com.nclg.exam.service.UserPaperService;
import com.nclg.exam.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/userPaper")
public class UserPaperController {

    @Autowired
    private UserPaperService userPaperService;

    /**
     * 查询用户考卷
     * @param dto
     * @return
     */
    @GetMapping("/selectByPage")
    public JsonResult selectByPage(UserPaperDto dto){
        PageInfo<UserPaperListDto> list = userPaperService.selectByPage(dto);
        LayResponse<UserPaperListDto> layResponse = new LayResponse("0", "", list.getTotal(), list.getList());
        return JsonResult.success(layResponse);
    }

    /**
     * 阅卷
     * @param dto
     * @return
     */
    @PostMapping("/reviewPaper")
    public JsonResult reviewPaper(ReviewPaperDto dto){
        boolean isTrue = userPaperService.updateReviewPaper(dto);
        if (!isTrue) return JsonResult.failure("阅卷失败");
        return JsonResult.success("阅卷结束");
    }
}
